//
//  OrderScheme.swift
//  eemall
//
//  Created by zhuxietong on 2019/5/9.
//  Copyright © 2019 zhuxietong. All rights reserved.
//

import Foundation
import soapp
import Eelay

extension Goods
{
    static let key_needAddress = "needaddress"
    static let key_wuliu_price = "dispatchprice"
    static let key_isverify = "isverify"
    public static var self_operated_tag = "自营".loc//自营商城标签
    public static var self_seller_name:String? = ""//自营商城标签
    public static var order_name:String = "订单".loc//订单|
    
    
    class Label: JoView {
        
        let tagBt = UIButton()
        let label = UILabel()
        
        var tagStr = Goods.self_operated_tag
        var text:String = ""
        {
            didSet{
                if tagStr.len > 0
                {
                    let tagAtr = "\(tagStr)".ui.font(font: UIFont.systemFont(ofSize: 9)).color(hex: "#fff").astring
                    tagBt.setAttributedTitle(tagAtr, for: .normal)
                    label.attributedText = "\(tagStr)   ".ui.lineSpace(4).font10.color(color: .clear).astring + text.ui.font13.color(hex: "#4C4C4C").lineSpace(4).astring
                    tagBt.alpha = 1
                }
                else
                {
                    let tagAtr = "\(tagStr)".ui.font(font: UIFont.systemFont(ofSize: 9)).color(hex: "#fff").astring
                    tagBt.setAttributedTitle(tagAtr, for: .normal)
                    tagBt.alpha = 0
                    label.attributedText = text.ui.font13.color(hex: "#4C4C4C").lineSpace(4).astring
                }
            }
        }
        
        
        override func addLayoutRules() {
            eelay = [
                [label,[ee.T.L.B.R]],
                [tagBt,[label,ee.T.L]],
            ]
            label.numberOfLines = 2
            tagBt.backgroundColor = UIColor(shex: "#E15378")
            tagBt.contentEdgeInsets = [3,4,3,4]
        }
        
        
    }
}




public protocol OrderSchemeSupport{
    var goodsTag:String{get}
    var sellerTag:String{get}
    var name:String{get}
    var supportSaleAfter:Bool{get}
    var orderListfilters:[Goods.OrderListFilter]{get}
    
    func barInfo(status:GoodsOrderStatus,obj:NSMutableDictionary)->(name:String,color:UIColor,icon:String,info:String,bt:String)
    func doAction(with btName:String,cell:JoCellNode?,at controller:UIViewController?,order:NSMutableDictionary)
    func actionButtons(status: GoodsOrderStatus)->(ASButtonStyle,ASButtonStyle)
}







public class OrderScheme:NSObject,OrderSchemeSupport{
    public override init() {
        super.init()
    }
    
    
    //售卖方案，针对部分客户需求，订单业务按：售卖、预约 区分显示
    public var scheme:OrderSchemeSupport = DefaultScheme()
    
    static public var `default`:OrderScheme = OrderScheme()
    
    public var sellerTag: String{
        return scheme.sellerTag
    }
    
    public var goodsTag:String{
        get{
            return scheme.goodsTag.loc
        }
    }
    public var name:String{
        get {
            return scheme.name.loc
        }
        
    }

    
    
    public var supportSaleAfter:Bool{
        get{
            return scheme.supportSaleAfter
        }
    }
    
    public var orderListfilters: [Goods.OrderListFilter]{
        get{
            return scheme.orderListfilters
        }
    }
    
    public func actionButtons(status: GoodsOrderStatus) -> (ASButtonStyle, ASButtonStyle) {
        return scheme.actionButtons(status: status)
    }
    
   
    
    public func barInfo(status:GoodsOrderStatus,obj:NSMutableDictionary)->(name:String,color:UIColor,icon:String,info:String,bt:String){
            return scheme.barInfo(status: status, obj: obj)
    }

    
    public func doAction(with btName:String,cell:JoCellNode?,at controller:UIViewController?,order:NSMutableDictionary) {
        return scheme.doAction(with: btName, cell: cell, at: controller, order: order)
    }
    
}
